//
//  HFVisitorViewController.swift
//  HFWeChat
//
//  Created by 黄来峰 on 16/4/18.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class HFVisitorViewController: UITableViewController {
    private var autoviewController: HFAutoLoginController?
    
    var visitorView: HFVisitorView?
    var isLogin:Bool = HFUserAccountTools.sharedTools.isLogin
    //MARK -加载View
    override func loadView(){
        //使用三目运算符
        isLogin ? super.loadView() : setUpVisitorView()
        
        
//        if isLogin{
//            super.loadView()
//            
//        }else{
//            
//            setUpVisitorView()
//            
//        }
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    //MARK -导航栏的相关设置
    func setUpNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerOrLoginClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "registerOrLoginClick")
        
        
    }
    
    
    //MARK -设置访客视图
    func setUpVisitorView(){
        visitorView = HFVisitorView()
        visitorView?.registerAndLoginButonClick = {
           self.registerOrLoginClick()
        }
        
        view = visitorView
        setUpNav()
        
}

    private lazy var autoViewcontroller: HFAutoLoginController = {
      let auto = HFAutoLoginController()
      return auto
    }()
    
    
    
     //MARK - 注册按钮的点击事件
    func registerOrLoginClick(){
        
//        presentViewController((autoViewcontroller), animated: true, completion: nil)
        presentViewController(UINavigationController(rootViewController: autoViewcontroller), animated: true, completion: nil)
    }
}

